# Debugging Git Tag Functionality
Write-Host "Debugging Git Tag Functionality"
Write-Host "============================="

# 检查当前git状态
Write-Host "Current git status:"
git status --porcelain

Write-Host ""
Write-Host "Current git tags:"
git tag

Write-Host ""
$version_number = Read-Host "Enter test version number (e.g., 1.9.9)"

# 检查标签是否已存在
Write-Host "Checking if tag v$version_number exists..."
$tag_exists = git tag --list | Select-String "v$version_number"

if ($tag_exists) {
    Write-Host "Tag v$version_number already exists"
    $delete_tag = Read-Host "Delete existing tag? (y/n)"
    if ($delete_tag -eq "y" -or $delete_tag -eq "Y") {
        Write-Host "Deleting tag v$version_number..."
        git tag -d "v$version_number"
        git push origin --delete "v$version_number"
    } else {
        Write-Host "Keeping existing tag"
        exit
    }
} else {
    Write-Host "Tag v$version_number does not exist"
}

# 创建测试标签
Write-Host "Creating tag v$version_number..."
git tag -a "v$version_number" -m "Debug test tag v$version_number"

if ($LASTEXITCODE -ne 0) {
    Write-Host "Error: Failed to create tag"
    Write-Host "Error code: $LASTEXITCODE"
    exit
}

Write-Host "Tag created successfully"

# 推送标签
Write-Host "Pushing tag to remote..."
git push origin "v$version_number"

if ($LASTEXITCODE -ne 0) {
    Write-Host "Error: Failed to push tag"
    Write-Host "Error code: $LASTEXITCODE"
    exit
}

Write-Host "Tag pushed successfully"

Write-Host ""
Write-Host "Debug script completed"
Read-Host "Press Enter to continue"